home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Frameworks / TransSkel 3.24 / Demos / C Demos / Button / Main.c < prev    next >
Text File  |  1995-03-21  |  3KB  |  142 lines

  1. /*
  2.  * Button - Demonstration of TransSkel button outlining for document windows,
  3.  * modeless dialogs, movable modal dialogs, and modal dialogs.  Accompanies
  4.  * discussion in TransSkel Programmer's Note 10.
  5.  *
  6.  * Also demonstrates key-to-button mapping for document windows, modeless
  7.  * dialogs, movable modal dialogs, and modal dialogs.
  8.  *
  9.  * Modal Dialog 1 demonstrates how to install an outliner for the button that's
  10.  * indicated as the default in the dialog template, and how to make the
  11.  * outline change state when the button does.
  12.  *
  13.  * Modal Dialog 2 demonstrates how to install an outliner when the button to
  14.  * be outlined isn't necessarily the default, and how to change the button
  15.  * with which the outline is associated.
  16.  *
  17.  * The document window demonstrates simple use of SkelDrawButtonOutline()
  18.  * in a document window.
  19.  *
  20.  * 11 Jan 94 Paul DuBois
  21.  *
  22.  * 11 Jan 94 Release 1.00
  23.  * 21 Feb 94
  24.  * - Updated for TransSkel 3.11.
  25.  * 22 Apr 94
  26.  * - Tracks cursor in dialogs so it becomes an I-beam in edit text items.
  27.  * 25 Apr 94
  28.  * - Escape and command-period in document window cause Cancel button to flash.
  29.  * 27 Apr 94 Release 1.01
  30.  * - Added modeless dialog.  It acts just like the document window, but is
  31.  * implemented differently.
  32.  * 28 Apr 94
  33.  * - Document window was wrong type (it had a grow region but shouldn't).
  34.  * Fixed.
  35.  * 30 Apr 94
  36.  * - Added movable modal dialog (not available unless running at least System 7).
  37.  * 01 May 94
  38.  * - Adjust menus when movable modal dialog is in front so a modal dialog can't
  39.  * be selected.
  40.  * 18 Aug 94
  41.  * - Updated for TransSkel 3.18 (Support for Universal headers, PowerPC,
  42.  * Metrowerks).
  43.  * 21 Mar 95
  44.  * - Updated for TransSkel 3.19.
  45.  * - Fixed bug with menu items not being adjusted properly the second and
  46.  * subsequent times the movable modeless dialog was displayed.
  47.  */
  48.  
  49. # include    "TransSkel.h"
  50.  
  51. # include    "Button.h"
  52.  
  53.  
  54. /*
  55.  * Handle selection of "About Button..." item from Apple menu
  56.  */
  57.  
  58. static pascal void
  59. DoAppleMenu (short item)
  60. {
  61.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  62.                                             skelPositionOnParentDevice);
  63.     SkelRmveDlogFilter ();
  64. }
  65. /*
  66.  * Process selection from File menu.
  67.  */
  68.  
  69. static pascal void
  70. DoFileMenu (short item)
  71. {
  72.     switch (item)
  73.     {
  74.     case doModal1:
  75.         DoModal1 ();
  76.         break;
  77.     case doModal2:
  78.         DoModal2 ();
  79.         break;
  80.     case doModal3:
  81.         DoModal3 ();
  82.         break;
  83.     case doMovable:
  84.         DoMovableModal ();
  85.         break;
  86.     case quitApp:
  87.         SkelStopEventLoop ();
  88.         break;
  89.     }
  90. }
  91.  
  92.  
  93. void
  94. AdjustMenus (void)
  95. {
  96. MenuHandle    m;
  97.  
  98.     m = GetMenuHandle (skelAppleMenuID);
  99.     if (SkelIsMMDlog (FrontWindow ()))    /* disable "About..." item */
  100.         DisableItem (m, 1);
  101.     else
  102.         EnableItem (m, 1);
  103.     m = GetMenuHandle (fileMenuRes);
  104.     if (SkelIsMMDlog (FrontWindow ()))
  105.     {
  106.         DisableItem (m, doModal1);
  107.         DisableItem (m, doModal2);
  108.         DisableItem (m, doModal3);
  109.         DisableItem (m, doMovable);
  110.     }
  111.     else
  112.     {
  113.         EnableItem (m, doModal1);
  114.         EnableItem (m, doModal2);
  115.         EnableItem (m, doModal3);
  116.         EnableItem (m, doMovable);
  117.     }
  118. }
  119.  
  120.  
  121. int
  122. main (void)
  123. {
  124. MenuHandle    m;
  125. long    result;
  126.  
  127.     SkelInit ((SkelInitParamsPtr) nil);    /* initialize */
  128.  
  129.     SkelApple ("\pAbout Button\311", DoAppleMenu);
  130.     m = GetMenu (fileMenuRes);
  131.     (void) SkelMenu (m, DoFileMenu, nil, false, true);
  132.     if (SkelQuery (skelQSysVersion) < 0x00000700)
  133.         DisableItem (m, doMovable);
  134.  
  135.     SetupDocument ();
  136.     SetupModeless ();
  137.  
  138.     SkelEventLoop ();
  139.  
  140.     SkelCleanup ();                        /* clean up */
  141. }
  142.